import axios from 'axios'

const request = axios.create({
    baseURL: '',
    timeout: 5000
})

request.interceptors.request.use(config => {
    if(localStorage.getItem('token')) {
        config.headers.Authorization = 'Bearer ' + localStorage.getItem('token')
    }
    return config
}, error => {
    return Promise.reject(error)
})

request.interceptors.response.use(response => {
    if(response.status === 200) {
        return response.data
    } else {
        Promise.reject(error)
    }
}, error => {
    return Promise.reject(error)
})

export default request